#pragma once
#include<time.h>
#include<stdlib.h>

#include"definition.h"
#include"snake.h"

extern Head snakehead;
extern Body snakebody;

class Fruit
{
public:
	bool isBlinking = false;
	int blinkTimer = 0;
	int rippleRadius = 0;
	bool isRippling = false;

	Fruit()
	{
		srand((int)time(0));
		x = rand()%GameSceneSizeHorizental+1;
		y = rand()%GameSceneSizeVirtical+1;
	}
	~Fruit() = default;

	bool Is_Eated()
	{
		if (x == snakehead.GetPosX() && y == snakehead.GetPosY())
		{
			return true;
		}
		for (int i = 0; i < snakebody.GetBodyLength(); i++)
		{
			if (x == snakebody[i].GetPosX() && y == snakebody[i].GetPosY())
			{
				return true;
			}
		}
		return false;
	}

	void Respawn()
	{
		if (Is_Eated())
		{
			cent++;
			if (cent % 5 == 0)
			{
				FPS++;
			}
			snakebody.grow();
			x = rand() % GameSceneSizeHorizental + 1;
			y = rand() % GameSceneSizeVirtical + 1;
			isBlinking = true;
			blinkTimer = 0;

			isRippling = true;
			rippleRadius = 0;
		}
	}

	void Reset()
	{
		x = rand() % GameSceneSizeHorizental + 1;
		y = rand() % GameSceneSizeVirtical + 1;
	}

	int GetPosX()
	{
		return x;
	}

	int GetPosY()
	{
		return y;
	}
private:
	int x, y;
};